package com.sys.SysGrowthRecords.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.sys.SysTanks.domain.SysTanks;
import com.sys.SysTanks.mapper.SysTanksMapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sys.common.annotation.Log;
import com.sys.common.core.controller.BaseController;
import com.sys.common.core.domain.AjaxResult;
import com.sys.common.enums.BusinessType;
import com.sys.SysGrowthRecords.domain.SysGrowthRecords;
import com.sys.SysGrowthRecords.service.ISysGrowthRecordsService;
import com.sys.common.utils.poi.ExcelUtil;
import com.sys.common.core.page.TableDataInfo;

/**
 * 生长记录Controller
 * 
 * @author sys
 * @date 2025-09-04
 */
@RestController
@RequestMapping("/SysGrowthRecords/SysGrowthRecords")
public class SysGrowthRecordsController extends BaseController
{
    @Autowired
    private ISysGrowthRecordsService sysGrowthRecordsService;
    @Autowired
    private SysTanksMapper sysTanksMapper;


    /**
     * 查询生长记录列表
     */
    @PreAuthorize("@ss.hasPermi('SysGrowthRecords:SysGrowthRecords:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysGrowthRecords sysGrowthRecords)
    {
        startPage();
        List<SysGrowthRecords> list = sysGrowthRecordsService.selectSysGrowthRecordsList(sysGrowthRecords);
        return getDataTable(list);
    }

    /**
     * 导出生长记录列表
     */
    @PreAuthorize("@ss.hasPermi('SysGrowthRecords:SysGrowthRecords:export')")
    @Log(title = "生长记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysGrowthRecords sysGrowthRecords)
    {
        List<SysGrowthRecords> list = sysGrowthRecordsService.selectSysGrowthRecordsList(sysGrowthRecords);
        ExcelUtil<SysGrowthRecords> util = new ExcelUtil<SysGrowthRecords>(SysGrowthRecords.class);
        util.exportExcel(response, list, "生长记录数据");
    }

    /**
     * 获取生长记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('SysGrowthRecords:SysGrowthRecords:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysGrowthRecordsService.selectSysGrowthRecordsById(id));
    }

    /**
     * 新增生长记录
     */
    @PreAuthorize("@ss.hasPermi('SysGrowthRecords:SysGrowthRecords:add')")
    @Log(title = "生长记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysGrowthRecords sysGrowthRecords)
    {
        // 判断养殖桶是否存在
        SysTanks tank = sysTanksMapper.selectSysTanksById(sysGrowthRecords.getTankId());
        if (tank == null) {
            return AjaxResult.error("养殖桶不存在");
        }
        return toAjax(sysGrowthRecordsService.insertSysGrowthRecords(sysGrowthRecords));
    }

    /**
     * 修改生长记录
     */
    @PreAuthorize("@ss.hasPermi('SysGrowthRecords:SysGrowthRecords:edit')")
    @Log(title = "生长记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysGrowthRecords sysGrowthRecords)
    {
        return toAjax(sysGrowthRecordsService.updateSysGrowthRecords(sysGrowthRecords));
    }

    /**
     * 删除生长记录
     */
    @PreAuthorize("@ss.hasPermi('SysGrowthRecords:SysGrowthRecords:remove')")
    @Log(title = "生长记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysGrowthRecordsService.deleteSysGrowthRecordsByIds(ids));
    }
}
